<?php namespace simpleFlow\app\module\admin\control\users;

use simpleFlow\request\RequestWeb as SFRequest;
use simpleFlow\app\model\user\User as User;
use simpleFlow\Session as SFSession;
use simpleFlow\view\html as SFHtml;
use simpleFlow\control\Control as SFControl;

class Control extends SFControl
{
	public function viewIndex(SFRequest $objRequest)
	{
		$ctrlUsers = new $this($this->objView,true);
		$this->objView->setFetchMode(true);
		$this->objView->viewLogin = $ctrlAdmin->viewLogin($objRequest);
		$this->objView->setFetchMode(false);
		
		//$objUser = new User;
		//$this->objView->listUsers = $objUser->readAll();
		return $this->renderView('list.tpl');
	}
	
	public function listUsers(SFRequest $objRequest)
	{
		/*for($i=0;$i<1000;$i++){
			$objUser = new User;
			$objUser->txUsername = 'user_'.$i;
			$objUser->txPassword = 'user_'.$i;
			$objUser->save();
		}*/

		$objUser = new User;
		$intPage = $objRequest->hasParam('page') ? $objRequest->getParam('page') : 1;
		
		$lsUsers = new SFHtml\ListView('lsUsers','Users',$this->objView);
		$lsUsers->addHeader(0, 'Cod', 5, 'Center');
		$lsUsers->addHeader(1, 'Username', 87);
		$lsUsers->setContent($objUser->readAll(false,$intPage),$objUser->count());
		$lsUsers->addActionButton('open', SF_URL_ROOT.'/admin/users/manageUser/id/', 'Manage User');
		$lsUsers->addActionButton('delete', SF_URL_ROOT.'/admin/users/delete/id/', 'Delete User', 'ui-icon-trash');
		$lsUsers->finish();
		
		unset($objUser);
		return $this->renderView('list.tpl');
	}
	
	public function manageUser(SFRequest $objRequest)
	{
		return $this->renderView('edit.tpl');
	}
}

?>